//
//  SCUserInfoViewModel.swift
//  weibo
//
//  Created by 阿城 on 15/12/8.
//  Copyright © 2015年 阿城. All rights reserved.
//

import UIKit

class SCUserInfoViewModel: NSObject {

    var userInfoMod:SCUserInfoModel?
    var token: String? {
        
        let timeInterval = userInfoMod?.expires_out?.timeIntervalSinceDate(NSDate())
        if let value = userInfoMod?.access_token where timeInterval > 0{
            return value
        }
        
        return nil
    }
    
    var isLogOn: Bool{
        return token != nil
    }
    
    static let shareInfoViewModel = SCUserInfoViewModel()
    
    private override init() {
        super.init()
        userInfoMod = loadInfo()
    }
    
    let archivePath = (NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true).first! as NSString).stringByAppendingPathComponent("Info.archive")
    
    func saveInfo(){
        NSKeyedArchiver.archiveRootObject(userInfoMod!, toFile: archivePath)
    }
    
    private func loadInfo() -> SCUserInfoModel?{
        let infoMod : SCUserInfoModel? = NSKeyedUnarchiver.unarchiveObjectWithFile(archivePath) as? SCUserInfoModel
        return infoMod
    }
}

extension SCUserInfoViewModel{
    
    
    
}

